package canvas
{
   import flash.display.*;
   import flash.geom.ColorTransform;
   import flash.geom.Rectangle;
   import flash.geom.Transform;

   /**
    * 用來做過場效果的畫布
    * @author   cjboy1984@gmail.com
    * @usage
    * 1. 取得畫布：
    *    MyCanvas.instance
    *
    * 2. 畫畫布：
    *    MyCanvas.draw(stage, sw, sh, false, 0x2B2B2B);
    *
    * 3. 清畫布：
    *    MyCanvas.clear();
    */
   public class MyCanvas extends Bitmap
   {
      public static var instance:Bitmap;

      /* constructor */
      public function MyCanvas();

      /**
       * Create the canvas.
       */
      public static function init():void
      {
         if (!MyCanvas.instance)
         {
            MyCanvas.instance = new Bitmap();
            MyCanvas.instance.smoothing = true;
         }
      }

      /**
       * Draws the source display object onto the bitmap image.
       * @param	src            The display object or BitmapData object to draw to the BitmapData object.
       * @param	w              The width of the canvas in pixels.
       * @param	h              The height of the canvas in pixels.
       * @param	transparent    Specifies whether the bitmap image  supports per-pixel transparency.
       * @param	fillColor      A 32-bit ARGB color value that you use to fill the bitmap image area.
       */
      public static function draw(src:IBitmapDrawable, w:Number, h:Number, transparent:Boolean = false, fillColor:uint = uint.MAX_VALUE):void
      {
         init();

         MyCanvas.instance.visible = false;
         MyCanvas.instance.bitmapData = new BitmapData(w, h, transparent, fillColor);
         MyCanvas.instance.bitmapData.draw(src);
         MyCanvas.instance.visible = true;
      }

      /**
       * Draws a rectangle onto the bitmap image.
       * @param	_x             The x-pos.
       * @param   _y             The y-pos.
       * @param	_w             The width of the canvas in pixels.
       * @param	_h             The height of the canvas in pixels.
       * @param	transparent    Specifies whether the bitmap image  supports per-pixel transparency.
       * @param	fillColor      A 32-bit ARGB color value that you use to fill the bitmap image area.
       */
      public static function fillRect(_x:Number, _y:Number, _w:Number, _h:Number, color:uint, transparent:Boolean = false, fillColor:uint = uint.MAX_VALUE):void
      {
         MyCanvas.instance.bitmapData = new BitmapData(_w, _h, transparent, fillColor);
         MyCanvas.instance.bitmapData.fillRect(new Rectangle(_x, _y, _w, _h), color);
      }

      /**
       * Clear the canvas (frees memory that is used to store the BitmapData object)
       */
      public static function clear():void
      {
         if (!MyCanvas.instance) return;
         if (!MyCanvas.instance.bitmapData) return;

         MyCanvas.instance.bitmapData.dispose();
      }

      // ------------------ LINE -------------------

      // ------------------ LINE -------------------

      // ------------------ LINE -------------------

   }

}